package com.dc.member.controller;

import com.dc.member.constants.WebConstants;
import com.dc.member.controller.req.vo.LoginVo;
import com.dc.web.base.BaseWebController;
import com.dc.web.utils.CookieUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author: KEYD
 * @Date: 2019/12/29 16:44
 * @Desc: 退出
 */
@Controller
public class ExitController extends BaseWebController {
    private static final String MEMBER_LOGIN_FTL = "member/login";  // 跳转到登录页面

    @GetMapping("/exit")
    public String postLogin(@ModelAttribute("loginVo") @Validated LoginVo loginVo, Model model,
                            HttpServletRequest request, HttpServletResponse response,
                            HttpSession httpSession) {
        //退出就是删除token
        CookieUtils.deleteCookie(request, response, WebConstants.LOGIN_TOKEN_COOKIENAME);
        //设置唯一登录
        //数据库已经设置好了，前端需要监听后台的数据
        return MEMBER_LOGIN_FTL;  //退出，跳转到首页
    }
}
